package com.kun;

import com.kun.domain.Student;
import com.kun.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;

/**
 * @author Nick fang
 * @date 2021/7/7 0007 - 下午 23:27
 */
public class MyApp2 {
    public static void main(String[] args) throws IOException {
        //【重要】获取sqlSession对象，从sqlSessionFactory中获取sqlSession
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        //【重要】指定要执行的SQL语句的标识（namespace.id）
        String sqlId = "com.kun.dao.StudentDao.selectStudents";
        //执行语句
        List<Student> studentList = sqlSession.selectList(sqlId);
        //输出结果
        studentList.forEach( stu ->System.out.println(stu));
        //关闭sqlsession对象
        sqlSession.close();;
    }
}
